package com.wuhongyu.service.impl;

import com.wuhongyu.base.BaseServiceImpl;
import com.wuhongyu.entity.Contact;
import com.wuhongyu.repository.ContactDao;
import com.wuhongyu.repository.CustomerDao;
import com.wuhongyu.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("contactService")
public class ContactServiceImpl extends BaseServiceImpl<Contact> implements ContactService {

    @Autowired
    private CustomerDao customerDao;

    private ContactDao contactDao;
    @Resource
    public void setDao(ContactDao contactDao){
        super.setBaseDao(contactDao);
        this.contactDao = contactDao;
    }

    public List<Contact> findAll(Integer customerid){
        return contactDao.findByCustomerEquals(customerDao.getOne(customerid));
    }

    @Override
    public void save(Contact contact) {
        contact.setCustomer(customerDao.getOne(contact.getCustomer().getId()));
        contactDao.saveAndFlush(contact);
    }

}